﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace StuMana
{
    public partial class MainForm : Form
    {
        private int ItemMenuIndex = 0;
        // Make instances of Panels
        UI.Activities Act = new UI.Activities();
        UI.Connect ConN = new UI.Connect();
        UI.Students AddS = new UI.Students();
        UI.CheckInOut ChIO = new UI.CheckInOut();
        UI.Help Help = new UI.Help();
        UI.Setting Sett = new UI.Setting();
        UI.SchoolLate schlate = new UI.SchoolLate();
        UI.Cafeteria cafe = new UI.Cafeteria();

        public string ts_stt="";

        public MainForm()
        {
            InitializeComponent();
        }
        private void MainForm_Load(object sender, EventArgs e)
        {
            SetBackImage(0);
            this.Controls.Add(ConN.getPanel(this.panel1.Location.X, this.panel1.Location.Y));

            settingsToolStripMenuItem.Enabled = true ;

            //settingsToolStripMenuItem.Enabled = false;
            
        }

        // Connect
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            SetBackImage(0);
            PanelChanging( 0);
            
        }


        //Students
        private void manageStudentToolStripMenuItem_Click(object sender, EventArgs e)
        {            
            SetBackImage(1);
            PanelChanging(1);
            AddS.InitialConnect(ConN.connect);            
            AddS.setStatus(ConN.setStatus());
        }    
        
        // Activities
        private void activitiesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SetBackImage(2);             
            PanelChanging(2);
            Act.setStatus(ConN.setStatus());
                    
        }

        //CheckInOut
        private void checkInOutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SetBackImage(3);
            PanelChanging(3);
            
            ChIO.InitialConnect(ConN.connect);
        }
        

        // schoolLate
        private void schoolLateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SetBackImage(4);
            PanelChanging(4);
        }

        //Cafeteria
        private void cafeteriaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SetBackImage(5);
            PanelChanging(5);
            cafe.InitialConnect(ConN.connect);
            cafe.setStatus(ConN.setStatus());
        }

        // Settings
        private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SetBackImage(6);
            PanelChanging(6);

           
        }

        // Help
        private void helpToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SetBackImage(7);
            PanelChanging(7);
        }

        // Set back ground of MenuItem
        private void SetBackImage(int CurIndex)
        {
            for (int i = 0; i < menuStrip1.Items.Count; i++)
            {
                if (i == CurIndex)
                    menuStrip1.Items[i].BackgroundImage = new Bitmap(StuMana.Properties.Resources.clicked);
                else
                    menuStrip1.Items[i].BackgroundImage = null;

            }
        }

        // Changing particular panel
        private void PanelChanging(int newIndex)
        {            
            switch(newIndex)
            {
                // Connect
                case 0:
                    if (ItemMenuIndex != 0)
                    {
                        this.Controls.Remove(Controls[1]);
                        this.Controls.Add(ConN.getPanel(this.panel1.Location.X, this.panel1.Location.Y));
                    }
                    ItemMenuIndex = 0;
                    break;
                case 1:
                    if (ItemMenuIndex != 1)
                    {
                        this.Controls.Remove(Controls[1]);
                        this.Controls.Add(AddS.getPanel(this.panel1.Location.X, this.panel1.Location.Y));
                    }
                    ItemMenuIndex = 1;
                    break;
                case 2:
                    if (ItemMenuIndex != 2)
                    {
                        this.Controls.Remove(Controls[1]);
                        this.Controls.Add(Act.getPanel(this.panel1.Location.X, this.panel1.Location.Y));
                    }
                    ItemMenuIndex = 2;
                    break;
                case 3:
                    if (ItemMenuIndex != 3)
                    {
                        this.Controls.Remove(Controls[1]);
                        this.Controls.Add(ChIO.getPanel(this.panel1.Location.X, this.panel1.Location.Y));
                    }
                    ItemMenuIndex = 3;
                    break;                    
                case 4:
                    if (ItemMenuIndex != 4)
                    {
                        this.Controls.Remove(Controls[1]);
                        this.Controls.Add(schlate.getPanel(this.panel1.Location.X, this.panel1.Location.Y));
                    }
               
                    ItemMenuIndex = 4;
                    break;
                case 5:
                    if (ItemMenuIndex != 5)
                    {
                       this.Controls.Remove(Controls[1]);
                        this.Controls.Add(cafe.getPanel(this.panel1.Location.X, this.panel1.Location.Y));
                    }
                    ItemMenuIndex = 5;
                    break;
                case 6:
                    if (ItemMenuIndex != 6)
                    {
                        this.Controls.Remove(Controls[1]);
                        this.Controls.Add(Sett.getPanel(this.panel1.Location.X, this.panel1.Location.Y));
                    }
                    ItemMenuIndex = 6;
                    break;

                case 7:
                    if (ItemMenuIndex != 7)
                    {
                        this.Controls.Remove(Controls[1]);
                        this.Controls.Add(Help.getPanel(this.panel1.Location.X, this.panel1.Location.Y));
                    }
                    ItemMenuIndex = 7;
                    break;
                default:
                    this.Controls.Add(ConN.getPanel(this.panel1.Location.X, this.panel1.Location.Y));
                    break;
            }
        }

      
    }
}
